package com.hutao.manage.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.hutao.manage.datasource.TargetDataSource;
import com.hutao.manage.mapper.FirstLevelMedicalMapper;
import com.hutao.manage.mapper.HospNoteVersionMapper;
import com.hutao.manage.mapper.HospitalNoteVersionMapper;
import com.hutao.manage.pojo.HospNoteVersion;
import com.hutao.manage.pojo.HospitalNoteVersion;
import com.hutao.manage.service.HospitalNoteVersionService;

@Transactional
@Service
public class HospitalNoteVersionServiceImpl implements HospitalNoteVersionService{
	@Autowired
	private HospNoteVersionMapper hospNoteVersionMapper;
	
	@Autowired
	private FirstLevelMedicalMapper firstLevelMedicalMapper;
	
	@TargetDataSource(name="ds1")
	@Transactional(propagation=Propagation.REQUIRED)
	@Override
	public int insertHospitalNoteVersion(HospNoteVersion hospNoteVersion) {
		return hospNoteVersionMapper.insert(hospNoteVersion);
	}

//	@Override
//	public HospitalNoteVersion findHospitalNoteVersionByFirstGuid(String firstGuid) {
//		return hospitalNoteVersionMapper.findHospitalNoteVersionByFirstGuid(firstGuid);
//	}

	/**
	 * 查询某份病案的所有历史版本
	 * 
	 */
	@TargetDataSource(name="ds1")
	@Transactional(readOnly = true)
	@Override
	public Map<String, Object> findHopitalNoteVersionListByFirstGuid(String firstGuid) {
		Map<String, Object> results = new HashMap<>();
		List<HospNoteVersion> hospitalNoteVersionList = hospNoteVersionMapper.findHopitalNoteVersionListByFirstGuid(firstGuid);
		Map<String, Object> firstLevleMedical = firstLevelMedicalMapper.findFirstLevelMedicalByFirstGuid(firstGuid);
		
		
		
		results.put("hospitalNoteVersionList", hospitalNoteVersionList);
		results.put("firstLevleMedical", firstLevleMedical);
		
		return results;
	}

	/**
	 * 通过主键查询某个历史版本
	 */
//	@TargetDataSource(name="ds1")
//	@Transactional(readOnly = true)
//	@Override
//	public HospitalNoteVersion findHospitalNoteVersionByGuid(String guid) {
//		return hospitalNoteVersionMapper.findHospitalNoteVersionByGuid(guid);
//	}

	
	
	
	
	
	
}
